package com.bigger.arch.app.web.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class BiggerAppAop {

    @Pointcut("execution(public * com.bigger.arch.app.web.controller.*Controller.*(..))")
    public void execute() {
        //System.out.println("执行中...");
    }

    @Before("execute()")
    public void before() {
        System.out.println("before...");
    }

    @After("execute()")
    public void after() {
        System.out.println("after...");
    }

    @AfterReturning("execute()")
    public void afterReturning() {
        System.out.println("afterReturning...");
    }

    @AfterThrowing("execute()")
    public void afterThrowing() {
        System.out.println("afterThrowing...");
    }

    @Around("execute()")
    public Object around(ProceedingJoinPoint joinPoint) {
        String title = joinPoint.getTarget().getClass().getName() + "." + joinPoint.getSignature().getName();
        try {
            System.out.println(title + " 执行开始...");
            return joinPoint.proceed();
        } catch (Throwable throwable) {
            System.out.println(title + " 执行异常...");
            throwable.printStackTrace();
            return null;
        } finally {
            System.out.println(title + " 执行结束...");
        }
    }

}
